

// store/index.js

import {legacy_createStore, applyMiddleware, compose} from 'redux'

import { thunk } from 'redux-thunk'

import reducer from './reducer.js'

// 使用redux-saga中间件将Saga与redux store建立连接
// 1、导入创建saga中间件函数
import createSagaMiddleware from'redux-saga'
// 3、需要拦截的action
import rootSaga from './sagas.js'
// 2、创建一个saga中间件
const sagaMiddleware = createSagaMiddleware()

// composeEnhancers 函数
// const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({trace: true}) || compose

const storeEnhancer = applyMiddleware(thunk, sagaMiddleware)
const store = legacy_createStore(reducer, composeEnhancers(storeEnhancer))
// 4、启动saga
sagaMiddleware.run(rootSaga)

export default store